package org.pc2r.protocole.message;

import java.util.ArrayList;
import java.util.List;

import org.pc2r.game.model.Position;
import org.pc2r.protocole.EnumRequest;
import static org.pc2r.protocole.RequestBuilder.*;

public class PutShipMessage extends Message {

	private List<Position> positions = new ArrayList<>();
	private boolean isHorizontal;
	
	public PutShipMessage() {
		super(EnumRequest.PUTSHIP);
	}
	
	public boolean addPosition(String x1, String y1) {		
		int x = -1;
		try {
			x = Integer.parseInt(x1);
		} catch(NumberFormatException e) {}
		
		boolean isValid = (x >= MIN_X && x <= MAX_X);
		if(isValid == false) return false;
		
		char y = y1.charAt(0);
		isValid = (y >= MIN_Y && y <= MAX_Y);
		if(isValid == false) return false;
		// On convertit pour que dans le tableau on est bien les bons indices
		// et pas des A - P ...
		int realY = y - MIN_Y;		
		return positions.add(new Position(x, realY));		
	}
	
	public List<Position> getPositions() {
		return positions;
	}

	@Override
	public String toString() {
		return positions.toString();
	}

  public boolean isHorizontal() {
    return isHorizontal;
  }

  public void setHorizontal(boolean isHorizontal) {
    this.isHorizontal = isHorizontal;
  }

}
